package com.bwie.controller;

import com.bwie.pojo.TbUser;
import com.bwie.service.TbUserService;
import com.bwie.utils.R;
import com.bwie.vo.LoginVo;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author 军哥
 * @version 1.0
 * @description: TODO
 * @date 2025/3/21 14:08
 */

@RestController
@RequestMapping("/user/index")
@RefreshScope
public class IndexContrller {

    @Autowired
    TbUserService tbUserService;

    @Value("${site.className}")
    private String className;

    /**
     * @description 根据ID获取用户信息
     * @params [userId]
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/3/21 14:11
     */
    @PostMapping("/getUserById/{userId}")
    public R getUserById(@PathVariable("userId") Integer userId) {
        return tbUserService.getUserById(userId);
    }

    /**
     * @description 管理员登录
     * @params []
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/3/21 14:55
     */
    @PostMapping("/login")
    public R login(@RequestBody LoginVo loginVo) {
        return tbUserService.login(loginVo);
    }

    /**
     * @description 分页获取商户
     * @params [pageInfoVo]
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/3/21 15:49
     */
    @PostMapping("/getUserList")
    public R getUserList(@RequestBody PageInfoVo pageInfoVo) {
        return tbUserService.getUserList(pageInfoVo);
    }

    /**
     * @description 商户注册
     * @params [tbUser]
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/3/22 10:06
     */
    @PostMapping("/addUser")
    public R addUser(@RequestBody @Validated TbUser tbUser) {
        return tbUserService.addUser(tbUser);
    }

    /**
     * @description 修改用户信息
     * @params [tbUser]
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/3/26 10:49
     */
    @PostMapping("/updateUser")
    public R updateUser(@RequestBody TbUser tbUser) {
        return tbUserService.updateUser(tbUser);
    }

    /**
     * @description 从nacos配置中心读取配置数据
     * @params []
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/3/24 11:08
     */
    @PostMapping("/getConfigFromNacos")
    public R getConfigFromNacos(){
        return tbUserService.getConfigFromNacos();
    }

    /**
     * @description 从nacos配置中心读取配置数据，但是不是用配置类
     * @params []
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/3/24 11:18
     */
    @PostMapping("/getConfigFromNacos2")
    public R getConfigFromNacos2(){
        System.out.println("className=" + className);
        return R.OK(className);
    }

    /**
     * @description 上传图片
     * @params [file]
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/3/25 10:31
     */
    @PostMapping("/uploadImage")
    public R uploadImage(@RequestPart("file") MultipartFile file) {
        return tbUserService.uploadImage(file);
    }

    /**
     * @description 获取用户角色列表
     * @params [userId]
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/3/25 11:17
     */
    @PostMapping("/getUserRole/{userId}")
    public R getUserRole(@PathVariable("userId") Integer userId) {
        return tbUserService.getUserRole(userId);
    }

    /**
     * @description 审核用户
     * @params [tbUser]
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/3/25 13:32
     */
    @PostMapping("/checkUser")
    public R checkUser(@RequestBody TbUser tbUser) {
        return tbUserService.checkUser(tbUser);
    }

    /**
     * 删除单个用户
     * @param userId
     * @return
     */
    @PostMapping("/deleteUserById/{userId}")
    public R deleteUserById(@PathVariable("userId") Integer userId) {
        return tbUserService.deleteUserById(userId);
    }

    /**
     * @description 批量删除用户
     * @params [userList]
     * @return com.bwie.utils.R
     * @author 军哥
     * @date 2025/3/26 11:17
     */
    @PostMapping("/deleteUserAll")
    public R deleteUserAll(@RequestBody List<TbUser> userList) {
        return tbUserService.deleteUserAll(userList);

    }

}
